package com.zhang.spark_2.com.zhang.core.transform

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @title:
 * @author: zhang
 * @date: 2022/2/12 16:29 
 */
object Spark02_groupBy_test {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("map")
    val sc = new SparkContext(conf)

    sc
      .textFile("data/apache.log")
      .map(
        line => {
          val datas: Array[String] = line.split(" ")
          val time: String = datas(3).split(":")(1)
          (time,1)
        }
      )
      .reduceByKey(_+_)
      .collect()
      .foreach(println)

    sc.stop()
  }

}
